import {createApp} from 'vue'
console.log(createApp);
import App from './App.vue'
import router from './router'
import store from './store'
import ELEMENT from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import hasMenu from './uitl/hasMenu'
//时间格式化
Date.prototype.format = function (fmt = 'yyyy-MM-dd HH:mm:ss') {
  /**
   * 日期数据
   */
  const opts = {
    'y+': this.getFullYear().toString(),
    'M+': (this.getMonth() + 1).toString(),
    'd+': this.getDate().toString(),
    'H+': this.getHours().toString(),
    'm+': this.getMinutes().toString(),
    's+': this.getSeconds().toString(),
    'f+': this.getMilliseconds().toString()
  }
  for (const key in opts) {
    const value = opts[key]; //时间值
    if (new RegExp(`(${key})`).test(fmt)) {
      const result = RegExp.$1; //如果匹配成功则可以获取到结果
      fmt = fmt.replace(result, value.padStart(result.length, '0'));
    }
  }
  return fmt;
}


import { fn } from './uitl/router'

function loadRoute() {
  let token = sessionStorage.getItem('token')
  let menulist = JSON.parse(localStorage.getItem('menusList'))
  console.log(41, menulist);
  setTimeout(() => {
    if (token && menulist) {
      let newlist = fn(menulist)
      newlist.forEach(item => {
        router.addRoute('homeview', item)
      })
    }
  }, 300)

}
loadRoute()

const app=createApp(App)
app.use(store)
app.use(router)
app.use(hasMenu)
app.use(ELEMENT,{
    locale: zhCn,
  })
app.mount('#app')
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
  }